// pages/cart/cart.js
import {getSetting,chooseAddress,openSetting,showToast} from "../../utils/asyncWx.js"

Page({
  data:{
    address:{},
    cart:[],
    totalPrice:0,
    totalNum:0
  },
  onShow(){
    // 获取缓存中的值
    const address=wx.getStorageSync("address")
    // console.log(address)
    let cart=wx.getStorageSync("cart")||[]
    cart=cart.filter(v=>v.checked)
    let totalPrice=0
    let totalNum=0
      cart.forEach(v => {
          totalPrice+=v.num*v.goods_price
          totalNum+=v.num
      })
       this.setData({
        cart,
        totalPrice,
        totalNum,
        address
       })
       wx.setStorageSync("cart", cart)
  },
  // 支付功能
  handleOrderPay(){
    const token=wx.getStorageSync('token');
      // 判断
      if(!token){
        wx.navigateTo({
          url: '/pages/auth/auth',
        })
      }
      console.log("已经存在token")
  }
  
})

